/*
 * @Descripttion: 
 * @version: 
 * @Author: yuanliutech
 * @Date: 2022-10-31 15:27:53
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2023-01-09 18:31:19
 */
Component({
  options: {
    styleIsolation: 'shared'
  },
  data: {
    active: 0,
    list: [{
        src: '/statics/images/index.png',
        srcActive: '/statics/images/index_sel.png',
        text: '首页',
        url: '/pages/index/index'
      },
      {
        src: '/statics/images/message.png',
        srcActive: '/statics/images/message_sel.png',
        text: '消息',
        url: '/pages/message/message'
      },
      {
        src: '/statics/images/personal.png',
        srcActive: '/statics/images/personal_sel.png',
        text: '个人中心',
        url: '/pages/personal-center/personal-center'
      },
    ],
    list1: [{
        src: '/statics/images/index.png',
        srcActive: '/statics/images/index_sel.png',
        text: '首页',
        url: '/pages/index/index'
      },
      {
        src: '/statics/images/message.png',
        srcActive: '/statics/images/message_sel.png',
        text: '消息',
        url: '/pages/consumer/message/message'
      },
      {
        src: '/statics/images/personal.png',
        srcActive: '/statics/images/personal_sel.png',
        text: '我的',
        url: '/pages/consumer/user/user'
      }
    ]
  },

  lifetimes: {
    attached() {
      // 获取全局数据
      const app = getApp();
      // console.log('监听app.globalData.rolename', app.globalData.rolename);
      if (app.globalData.rolename === 'HOME_CONSUMER') {
        let {
          list,
          list1
        } = this.data

        this.setData({
          list: list1,
        })
      }

      // 监听全局数据变化,监听器
      // this.watchGlobalData();
    },
  },



  methods: {

    watchGlobalData() {
      const app = getApp();
      Object.defineProperty(app.globalData, 'rolename', {
        configurable: true,
        enumerable: true,
        set: (value) => {
          console.log('监听value', value);
          this.setData({
            rolename: value
          });
        },
        get: () => {
          return this.data.rolename;
        },
      });
    },

    onChange(event) {
      this.setData({
        active: event.detail
      });
      wx.switchTab({
        url: this.data.list[event.detail].url
      });
    },

    init() {
      const page = getCurrentPages().pop();
      this.setData({
        active: this.data.list.findIndex(item => item.url === `/${page.route}`)
      });
    }
  }
});